using UnityEngine;

namespace Crosstales.Common.Util
{
    // [Assembly-CSharp-firstpass.dll].Crosstales.Common.Util.NetworkHelper
    public abstract class NetworkHelper
    {
        
        #region Crosstales.Common.Util.NetworkHelper.<>c
        // [Assembly-CSharp-firstpass.dll].Crosstales.Common.Util.NetworkHelper.<>c
        [Serializable]
        private sealed class __c
        {
            // Fields
            public static readonly Crosstales.Common.Util.NetworkHelper.<>c __9;
            public static System.Func<System.Security.Cryptography.X509Certificates.X509ChainStatus, bool> __9__5_0;
            
            // Methods
            private static __c()
            {
                object val_1 = 536899471;
                val_1 = new System.Object();
                mem2[0] = val_1;
                throw new NullReferenceException();
            }
            public __c()
            {
            
            }
            internal bool <RemoteCertificateValidationCallback>b__5_0(System.Security.Cryptography.X509Certificates.X509ChainStatus t)
            {
                return (bool)(t.status != 64) ? 1 : 0;
            }
        
        }
        
        #endregion
        
        // Fields
        protected const string file_prefix = "file://";
        protected const string content_prefix = "content://";
        
        // Properties
        public static bool isInternetAvailable { get; }
        
        // Methods
        public static bool get_isInternetAvailable()
        {
            if((Crosstales.Common.Util.Singleton<System.Object>.Instance) == 0)
            {
                    UnityEngine.NetworkReachability val_3 = UnityEngine.Application.internetReachability;
                return (bool)((val_4 + 121) != 0) ? 1 : 0;
            }
            
            Unknown val_4 = Crosstales.Common.Util.Singleton<System.Object>.Instance;
            return (bool)((val_4 + 121) != 0) ? 1 : 0;
        }
        public static bool OpenURL(string url)
        {
            if((Crosstales.Common.Util.NetworkHelper.isValidURL(url:  url)) != false)
            {
                    UnityEngine.Application.OpenURL(url:  url);
                return false;
            }
            
            UnityEngine.Debug.LogWarning(message:  -1610602029(-1610602029) + url);
            return false;
        }
        public static bool RemoteCertificateValidationCallback(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
        {
            System.Func<Unknown, System.Boolean> val_15;
            System.Collections.Generic.IEnumerable<Unknown> val_16;
            System.Security.Cryptography.X509Certificates.X509Certificate2 val_17;
            var val_18;
            System.Func<Unknown, System.Boolean> val_19;
            var val_20;
            var val_21;
            var val_22;
            var val_23;
            var val_24;
            var val_25;
            var val_26;
            var val_27;
            var val_28;
            val_16 = sslPolicyErrors;
            val_17 = certificate;
            if(val_16 != 0)
            {
                    if(chain == null)
            {
                    throw new NullReferenceException();
            }
            
                val_18 = 27363104;
                val_19 = 0;
                val_20 = 536899471;
                val_16 = chain.ChainStatus;
                if(mem[536899695] == 0)
            {
                    val_20 = 536899471;
            }
            
                val_15 = mem[mem[536899655] + 8];
                val_15 = mem[536899655] + 8;
                if(val_15 == 0)
            {
                    if(mem[536899695] == 0)
            {
                    val_20 = 536899471;
            }
            
                System.Func<System.Security.Cryptography.X509Certificates.X509ChainStatus, System.Boolean> val_2 = 536903221;
                if(val_2 == 0)
            {
                    throw new NullReferenceException();
            }
            
                val_15 = val_2;
                val_2 = new System.Func<System.Security.Cryptography.X509Certificates.X509ChainStatus, System.Boolean>(object:  mem[536899655], method:  1610683719);
                mem2[0] = val_15;
            }
            
                val_19 = val_15;
                System.Collections.Generic.IEnumerable<Unknown> val_3 = System.Linq.Enumerable.Where<System.Security.Cryptography.X509Certificates.X509ChainStatus>(source:  val_16, predicate:  val_19);
                if(val_3 == null)
            {
                    throw new NullReferenceException();
            }
            
                val_21 = val_3;
            }
            else
            {
                    val_22 = 1;
                return (bool)1 & 1;
            }
            
            val_18 = 27348040;
            val_16 = val_3;
            val_22 = 1;
            label_30:
            val_23 = val_16;
            if((val_16 & 1) == 0)
            {
                goto label_18;
            }
            
            val_24 = val_16;
            val_19 = 0;
            System.Security.Cryptography.X509Certificates.X509ChainPolicy val_7 = chain.ChainPolicy;
            if(val_7 == null)
            {
                    throw new NullReferenceException();
            }
            
            val_7.RevocationFlag = 1;
            val_19 = 0;
            System.Security.Cryptography.X509Certificates.X509ChainPolicy val_8 = chain.ChainPolicy;
            if(val_8 == null)
            {
                    throw new NullReferenceException();
            }
            
            val_8.RevocationMode = 1;
            val_19 = 0;
            System.TimeSpan val_10 = new System.TimeSpan(hours:  0, minutes:  1, seconds:  0);
            if(chain.ChainPolicy == null)
            {
                    throw new NullReferenceException();
            }
            
            val_9.timeout = val_10._ticks;
            val_19 = 0;
            System.Security.Cryptography.X509Certificates.X509ChainPolicy val_11 = chain.ChainPolicy;
            if(val_11 == null)
            {
                    throw new NullReferenceException();
            }
            
            val_11.VerificationFlags = 255;
            if(val_17 != null)
            {
                    val_19 = 536896071;
            }
            
            bool val_12 = chain.Build(certificate:  val_17);
            goto label_30;
            label_18:
            val_17 = 0;
            label_51:
            if(val_16 != null)
            {
                    val_25 = val_16;
            }
            
            if(val_17 == 0)
            {
                    return (bool)1 & 1;
            }
            
            val_26 = val_19;
            val_27 = val_17;
            if( != 1)
            {
                goto label_50;
            }
            
            goto label_51;
            label_50:
            if(val_16 == null)
            {
                goto label_59;
            }
            
            label_58:
            val_28 = val_16;
            label_59:
            if(val_16 != null)
            {
                goto label_58;
            }
            
            goto label_59;
        }
        public static string ValidURLFromFilePath(string path)
        {
            if((System.String.IsNullOrEmpty(value:  path)) != false)
            {
                    return (string)path;
            }
            
            if((Crosstales.Common.Util.NetworkHelper.isValidURL(url:  path)) == false)
            {
                    return Crosstales.Common.Util.BaseConstants.PREFIX_FILE + System.Uri.EscapeUriString(stringToEscape:  Crosstales.Common.Util.FileHelper.ValidateFile(path:  path).Replace(oldChar:  '\', newChar:  '/'))(System.Uri.EscapeUriString(stringToEscape:  Crosstales.Common.Util.FileHelper.ValidateFile(path:  path).Replace(oldChar:  '\', newChar:  '/')));
            }
            
            if(mem[536895485] != 0)
            {
                    return System.Uri.EscapeUriString(stringToEscape:  Crosstales.Common.Util.FileHelper.ValidateFile(path:  path).Replace(oldChar:  '\', newChar:  '/'));
            }
            
            return System.Uri.EscapeUriString(stringToEscape:  Crosstales.Common.Util.FileHelper.ValidateFile(path:  path).Replace(oldChar:  '\', newChar:  '/'));
        }
        public static string CleanUrl(string url, bool removeProtocol = True, bool removeWWW = True, bool removeSlash = True)
        {
            var val_8;
            string val_9;
            val_8 = removeProtocol;
            if(url != null)
            {
                    val_9 = url.Trim();
            }
            else
            {
                    val_9 = 0;
            }
            
            if((System.String.IsNullOrEmpty(value:  url)) == true)
            {
                    return val_9;
            }
            
            if(val_8 != false)
            {
                    val_8 = 27483472;
                string val_8 = -1610611449;
                val_8 = (Crosstales.ExtensionMethods.CTIndexOf(str:  val_9, toCheck:  val_8, comp:  5)) + 2;
                val_9 = val_9.Substring(startIndex:  val_8);
            }
            
            if(removeWWW != false)
            {
                    val_8 = 27548864;
                val_9 = Crosstales.ExtensionMethods.CTReplace(str:  val_9, oldString:  -1610595089, newString:  mem[536893213], comp:  5);
            }
            
            if(removeSlash == false)
            {
                    return val_9;
            }
            
            if((Crosstales.ExtensionMethods.CTEndsWith(str:  val_9, toCheck:  -1610611453, comp:  5)) == false)
            {
                    return val_9;
            }
            
            return val_9.Substring(startIndex:  0, length:  val_5._stringLength - 1);
        }
        public static bool isValidURL(string url)
        {
            if((System.String.IsNullOrEmpty(value:  url)) != false)
            {
                    return true;
            }
            
            if((url.StartsWith(value:  -1610598705, comparisonType:  5)) == true)
            {
                    return true;
            }
            
            if((url.StartsWith(value:  -1610599645, comparisonType:  5)) == true)
            {
                    return true;
            }
            
            if((url.StartsWith(value:  -1610598213, comparisonType:  5)) == false)
            {
                    return url.StartsWith(value:  -1610598145, comparisonType:  5);
            }
            
            return true;
        }
        public static string GetIP(string host)
        {
            string val_4 = host;
            if((System.String.IsNullOrEmpty(value:  val_4 = host)) != false)
            {
                    UnityEngine.Debug.LogWarning(message:  -1610606931);
                return (string)val_4;
            }
            
            Unknown val_2 = System.Net.Dns.GetHostAddresses(hostNameOrAddress:  val_4);
            if(val_2 == null)
            {
                    throw new NullReferenceException();
            }
            
            if(val_2.Length == 0)
            {
                    throw new NullReferenceException();
            }
            
            val_4 = val_2[0];
            return (string)val_4;
        }
        private static void openURL(string url)
        {
            UnityEngine.Application.OpenURL(url:  url);
        }
        protected NetworkHelper()
        {
        
        }
    
    }

}
